<template>
    <div style="display: flex;">
       <div id="main" style="width:600px;height:400px;margin-right:10px;" class="card"></div>
       <div id="main2" style="width:600px;height:400px;" class="card"></div>
    </div>
</template>
<script setup>
    import {reactive,onMounted} from 'vue'
    import {Search} from '@element-plus/icons-vue'
    import * as echarts from 'echarts'
import request from '@/utils/request'

    const option={
            title:{
                text:'各机构人员数量'
            },
            tooltip:{},
            legend:{
                data:['人数']
            },
            xAxis:{
                data:[]
            },
            yAxis:{},
            series:[
                {
                    name:'人数',
                    type:'bar',
                    data:[],
                    itemStyle:{
                        normal:{
                            color:function(params){
                                let colors = ['red','blue','green','yellow']
                                return colors[params.dataIndex % colors.length]
                            }
                        }
                    }
                }
            ]
        }
    
    const option2={
        xAxis: {
    type: 'category',
    data: ['A', 'B', 'C']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [120, 200, 150],
      type: 'line'
    }
  ]
    }

    const data = reactive({
        
    })

    //dom初始化完成才能初始化图表
    onMounted(()=>{
        const myChart = echarts.init(document.getElementById('main'))
        request.get("/system/user/barData").then(res=>{
            option.xAxis.data = res.data.org
            option.series[0].data = res.data.count
            myChart.setOption(option)
        })
        
        const myChart2 = echarts.init(document.getElementById('main2'))
        myChart2.setOption(option2)
    })
</script>